package hu.debrecen.adastra.card.web.resolver;

import java.lang.annotation.Annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.core.MethodParameter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;

public abstract class AutowiredHandlerAnnotationArgumentResolver implements HandlerMethodArgumentResolver {

	@Target(ElementType.PARAMETER)
	@Retention(RetentionPolicy.RUNTIME)
	@Documented
	public static @interface AutowiredHandler {
	}

	@Override
	public boolean supportsParameter(final MethodParameter paramMethodParameter) {
		return this.contains(paramMethodParameter.getParameterAnnotations(), AutowiredHandler.class);
	}

	private boolean contains(final Annotation[] parameterAnnotations, final Class<AutowiredHandler> clazz) {

		for (Annotation annotation : parameterAnnotations) {
			if (clazz.isInstance(annotation)) {
				return true;
			}
		}

		return false;
	}

}
